package net.xxcl.kygl.service;

import java.util.List;
import net.xxcl.kygl.mapper.ProjectTypeMapper;
import net.xxcl.kygl.pojo.Criteria;
import net.xxcl.kygl.pojo.ProjectType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional()
public class ProjectTypeService {
    @Autowired
    private ProjectTypeMapper projectTypeMapper;

    private static final Logger logger = LoggerFactory.getLogger(ProjectTypeService.class);

    @Transactional(readOnly = true)
    public int countByExample(Criteria example) {
        int count = this.projectTypeMapper.countByExample(example);
        logger.debug("count: {}", count);
        return count;
    }

    @Transactional(readOnly = true)
    public ProjectType selectByPrimaryKey(Integer id) {
        return this.projectTypeMapper.selectByPrimaryKey(id);
    }

    @Transactional(readOnly = true)
    public List<ProjectType> selectByExample(Criteria example) {
        return this.projectTypeMapper.selectByExample(example);
    }

    public int deleteByPrimaryKey(Integer id) {
        return this.projectTypeMapper.deleteByPrimaryKey(id);
    }

    public int updateByPrimaryKeySelective(ProjectType record) {
        return this.projectTypeMapper.updateByPrimaryKeySelective(record);
    }

    public int updateByPrimaryKey(ProjectType record) {
        return this.projectTypeMapper.updateByPrimaryKey(record);
    }

    public int deleteByExample(Criteria example) {
        return this.projectTypeMapper.deleteByExample(example);
    }

    public int updateByExampleSelective(ProjectType record, Criteria example) {
        return this.projectTypeMapper.updateByExampleSelective(record, example);
    }

    public int updateByExample(ProjectType record, Criteria example) {
        return this.projectTypeMapper.updateByExample(record, example);
    }

    public int insert(ProjectType record) {
        return this.projectTypeMapper.insert(record);
    }

    public int insertSelective(ProjectType record) {
        return this.projectTypeMapper.insertSelective(record);
    }

    /**
     * 删除课题类型
     * @param ids
     * @return
     */
    public int deleteProjectType(String ids) {
        String[] str = ids.split(",");
        for(String id:str){
            this.projectTypeMapper.deleteByPrimaryKey(Integer.parseInt(id));
        }
        return str.length;
    }
}